﻿using System;
using System.Linq;
using System.Windows.Forms;

namespace e_TicaretAdmin_Application
{
    public partial class YeniKategori : Form
    {
        public int? Id { get; set; }
        private Category _category = new Category();
        public YeniKategori()
        {
            InitializeComponent();
        }
        private void YeniKategori_Load(object sender, EventArgs e)
        {
            if (Id.HasValue)
            {
                _category = Program.Db.Categories.SingleOrDefault(d => d.Id == Id.Value);
                if (_category != null)
                {
                    txtKategori.Text = _category.Text;
                    txtSeo.Text = _category.SeoText;
                    txtSeriNo.Text = _category.OrderNumber.ToString();
                }
            }
        }

        private void btnKaydet_Click(object sender, EventArgs e)
        {
            _category.Text = txtKategori.Text;
            _category.SeoText = txtSeo.Text;
            _category.OrderNumber = short.Parse(txtSeriNo.Text);
            if (!Id.HasValue)
                Program.Db.Categories.InsertOnSubmit(_category);
            Program.Db.SubmitChanges();
            Close();
        }
    }
}

